Arithmetic operators are used to perform arithmetic operations on variables and data.
Operator | Operation |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulo Operation (Remainder after division) |
++ | Increment |
-- | Decrement |
Assignment operators are used to assign values to variables.
Operator | Operation | Equivalent to |
---|---|---|
= | a=b | a=b; |
+= | a+=b | a=a+b |
-= | a-=b | a=a-b |
*= | a*=b | a=a*b |
/= | a/=b | a=a/b |
%= | a%=b | a=a%b |
A relational operator is used to check the relationship between two operands.
Operator | Meaning |
---|---|
< | Less Than |
> | Greater Than |
<= | Greater Than or Equal To |
>= | Less Than or Equal To |
== | is Equal To |
!= | Not Equal To |
Logical operators are used to check whether an expression is true or false.
Operator | Meaning |
---|---|
&& | Logical AND. True only if all the operands are true. |
|| | Logical OR. True if at least one of the operands is true. |
! | Logical NOT. True only if the operand is false. |
If an expression contains different operators then they are evaluated according to their precedence.
Precedence | Operator | Description | Associativity |
---|---|---|---|
1 | a++ a-- |
Suffix/postfix increment Suffix/postfix decrement |
Left to Right |
2 | ++a --a |
Prefix increment Prefix decrement |
Right to Left |
3 | a * b a / b a % b |
Multiplication Division Modulus |
Left to Right |
4 | a + b a - b |
Addition Subtraction |
Left to Right |
5 | < <= > >= |
Less than Less than or equal to Greater than Greater than or equal to |
Left to Right |
6 | == != |
Equal to Not equal to |
Left to Right |
7 | && | Logical AND | Left to Right |
8 | || | Logical OR | Left to Right |